import { defineMock } from 'vite-plugin-mock-dev-server'

export default defineMock([
  {
    url: '/api/category/:id',
    method: 'GET',
    body: (req) => {
      const categoryId = req.params.id
      // 根据不同的catid返回不同的数据
      const categoryData = {
        '1': [
          {
            id: 11,
            title: '首页推荐文章1',
            link: '/article/11',
            image: 'https://images.unsplash.com/photo-1499750310107-5fef28a66643?w=400&h=300&fit=crop',
            rating: '★★★★★',
            description: '这是首页推荐的第一篇文章，内容精彩纷呈。'
          },
          {
            id: 12,
            title: '首页热门文章',
            link: '/article/12',
            image: 'https://images.unsplash.com/photo-1454165804606-c3d57bc86b40?w=400&h=300&fit=crop',
            rating: '★★★★',
            description: '热门文章推荐，不容错过的精彩内容。'
          }
        ],
        '2': [
          {
            id: 21,
            title: '社会热点分析',
            link: '/article/21',
            image: 'https://images.unsplash.com/photo-1434626881859-194d67b2b86f?w=400&h=300&fit=crop',
            rating: '★★★★',
            description: '深入分析当前社会热点问题，提供独到见解。'
          },
          {
            id: 22,
            title: '历史文化探秘',
            link: '/article/22',
            image: 'https://images.unsplash.com/photo-1532012197267-da84d127e765?w=400&h=300&fit=crop',
            rating: '★★★★★',
            description: '探索历史文化的奥秘，了解文明的发展历程。'
          },
          {
            id: 23,
            title: '文学经典赏析',
            link: '/article/23',
            image: 'https://images.unsplash.com/photo-1481627834876-b7833e8f5570?w=400&h=300&fit=crop',
            rating: '★★★',
            description: '欣赏文学经典作品，感受文字的魅力。'
          }
        ],
        '3': [
          {
            id: 31,
            title: 'PHP开发实战',
            link: '/article/31',
            image: 'https://images.unsplash.com/photo-1555066931-4365d14bab8c?w=400&h=300&fit=crop',
            rating: '★★★★',
            description: 'PHP开发实战经验分享，提升编程技能。'
          },
          {
            id: 32,
            title: 'MySQL优化技巧',
            link: '/article/32',
            image: 'https://images.unsplash.com/photo-1542751110-97427bbecf20?w=400&h=300&fit=crop',
            rating: '★★★★★',
            description: 'MySQL数据库优化技巧，提升查询性能。'
          },
          {
            id: 33,
            title: 'HTML5新特性',
            link: '/article/33',
            image: 'https://images.unsplash.com/photo-1542831371-29b0f74f9713?w=400&h=300&fit=crop',
            rating: '★★★',
            description: '探索HTML5的新特性和应用场景。'
          },
          {
            id: 34,
            title: 'CSS3动画效果',
            link: '/article/34',
            image: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=400&h=300&fit=crop',
            rating: '★★★★',
            description: '学习CSS3动画效果，打造炫酷界面。'
          },
          {
            id: 35,
            title: 'JavaScript高级技巧',
            link: '/article/35',
            image: 'https://images.unsplash.com/photo-1627398242454-45a1465c2479?w=400&h=300&fit=crop',
            rating: '★★★★★',
            description: '掌握JavaScript高级编程技巧。'
          }
        ],
        '4': [
          {
            id: 41,
            title: '诗词赏析',
            link: '/article/41',
            image: 'https://images.unsplash.com/photo-1544716278-ca5e3f4abd8c?w=400&h=300&fit=crop',
            rating: '★★★★',
            description: '欣赏经典诗词，感受文学之美。从《望庐山瀑布》感受唐朝诗人的浪漫气质：“庐山瀑布，瀑布之名，非指其高度，而指其宽度。”'
          },
          {
            id: 42,
            title: '书法艺术',
            link: '/article/42',
            image: 'https://images.unsplash.com/photo-1541961017774-22349e4a1262?w=400&h=300&fit=crop',
            rating: '★★★',
            description: '了解书法艺术的历史和技巧。'
          }
        ],
        '5': [
          {
            id: 51,
            title: '冥想入门',
            link: '/article/51',
            image: 'https://images.unsplash.com/photo-1544367567-0f2fcb009e0b?w=400&h=300&fit=crop',
            rating: '★★★★★',
            description: '学习冥想的基本方法和好处。'
          },
          {
            id: 52,
            title: '健康生活方式',
            link: '/article/52',
            image: 'https://images.unsplash.com/photo-1498837167922-ddd27525d352?w=400&h=300&fit=crop',
            rating: '★★★★',
            description: '培养健康的生活习惯和方式。'
          }
        ],
        '6': [
          {
            id: 61,
            title: '联系我们',
            link: '/contact',
            image: 'https://images.unsplash.com/photo-1516321318423-f06f85e504b3?w=400&h=300&fit=crop',
            rating: '★★★★★',
            description: '获取联系方式和沟通渠道。'
          }
        ]
      }

      // 返回对应分类的数据，如果没有找到则返回空数组
      const data = categoryData[categoryId] || []

      return {
        code: 0,
        msg: 'success',
        data: data,
        categoryInfo: {
          id: categoryId,
          name: getCategoryName(categoryId),
          total: data.length
        }
      }
    },
    enabled: true,
  },
  {
    url: '/api/breadcrumb/:categoryId?',
    method: 'GET',
    body: (req) => {
      const categoryId = req.params.categoryId
      const categoryName = getCategoryName(categoryId)

      const breadcrumbData = {
        base: [
          { 
            label: '首页', 
            to: { path: '/' }, 
            icon: 'i-ep-house'
          }
        ],
        withCategory: [
          { 
            label: '首页', 
            to: { path: '/' }, 
            icon: 'i-ep-house'
          },
          { 
            label: categoryName, 
            to: null, 
            icon: 'i-ep-folder'  
          }
        ]
      }

      return {
        code: 0,
        msg: 'success',
        data: categoryId ? breadcrumbData.withCategory : breadcrumbData.base
      }
    },
    enabled: true,
  }
])

// 辅助函数：根据分类ID获取分类名称
function getCategoryName(categoryId) {
  const categoryNames = {
    '1': '首页推荐',
    '2': '网摘文章',
    '3': '技术大杂烩',
    '4': '舞文弄墨',
    '5': '修身养性',
    '6': '联系我'
  }
  return categoryNames[categoryId] || '未知分类'
}